package com.camera.yl.v

import android.view.View
import androidx.lifecycle.Observer
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.camera.base.util.YLBaseConfig
import com.camera.base.v.BaseActivity
import com.camera.routemodule.RouterPath
import com.camera.yl.R
import com.camera.yl.databinding.ActivityMediaSettingBinding
import com.camera.yl.dialog.NumberPickerDialog
import com.camera.yl.v.models.MediaSettingViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = RouterPath.path.mediaSetting_talk)
class MediaSettingActivity: BaseActivity<ActivityMediaSettingBinding,MediaSettingViewModel>() {
    val TAG = MediaSettingActivity::class.java.simpleName
    override val viewModelClass: Class<MediaSettingViewModel>
        get() = MediaSettingViewModel::class.java
    private var mNumberPickerDialog:NumberPickerDialog? =null
    override fun getLayoutId(): Int {
        return R.layout.activity_media_setting
    }

    override fun getStatusBarColor(): Int {
        return R.color.title_background_color
    }


    override fun loadData() {
        //获取一个随机数
        mBinding.viewModel = viewModel
        viewModel.SS = getString(R.string.SS)
        viewModel.MM = getString(R.string.MM)
        viewModel.windowManagerChoose.observe(this, Observer {
            viewModel.setWindowManagerChoose()
        })
        viewModel.cyclicStorageChoose.observe(this, Observer {
            YLBaseConfig.setCyclicStorage(it)
        })
        viewModel.externalStorageChoose.observe(this, Observer {
            YLBaseConfig.setExternalStorage(it)
        })
        viewModel.preRecordSwitch.observe(this, Observer {
            viewModel.setPreRecordSwitch()
        })
        viewModel.delayRecordSwitch.observe(this, Observer {
            viewModel.setDelayRecordSwitch()
        })
        viewModel.videoDecoderChoose.observe(this, Observer {
            viewModel.setVideoDecoderType()
        })
        viewModel.cameraApiChoose.observe(this, Observer {
            viewModel.setCameraApiChoose()
        })
        viewModel.showRecordSegmented(getString(R.string.MM),getString(R.string.SS))
        viewModel.showNumberPickerDialog.observe(this, Observer {
            if (it.value2 && it.value3 != null){
                val titleDialog = when (it.value1){
                    R.id.btn_video_record_segmented_set -> this.getString(R.string.video_record_segmenteds)
                    else -> ""
                }
                mNumberPickerDialog = NumberPickerDialog(this, titleDialog, it.value3!!, { selectedValue ->
                    viewModel.saveData(it.value1,selectedValue,it.value3!![selectedValue])
                })
                mNumberPickerDialog?.show()
            }else{
                mNumberPickerDialog?.dismiss()
            }
        })
    }

    override fun initView() {
    }
//    @SingleClick
    fun myClick(view: View) {
        when (view.id) {
            R.id.btn_video_record_segmented_set,
            R.id.btn_video_record_quality_set,
            R.id.btn_video_sub_strame_quality_set,
            R.id.btn_video_sub_strame_fps_set,
            R.id.btn_video_record_rate_set,
            R.id.btn_capture_size_set,
            R.id.btn_video_prerecord_set,
            R.id.btn_video_sub_strame_rotate_set,
            R.id.btn_video_derecord_set -> {
                viewModel.showNumberPickerDialog(view.id)
            }
            R.id.btn_video_mark_water ->{
                ARouter.getInstance().build(RouterPath.path.watermark_setting_activity).withTransition(R.anim.slide_in_right, R.anim.slide_out_left).navigation()
            }
            //,
            //            R.id.btn_video_sub_strame_rate_set
        }
    }


}